<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2019/1/25
 * Time: 14:07
 */

namespace app\api\model;


class MessageFormid  extends BaseModel
{
    protected $autoWriteTimestamp = true;

    /**
     * 创建formid
     * @param $formId
     * @param $wu_id
     * @param $uid
     * @return $this
     */
    public static function  createFormId($formId,$wu_id,$uid){
        $data['formId'] = $formId;
        $data['wu_id'] = $wu_id;
        $data['uid'] = $uid;
        return self::create($data);
    }

    /**
     * 获取能用的formid
     * @param $wu_id
     * @param $uid
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public static function getFormId($wu_id,$uid){
        $time = time()-7*24*3600;
        self::where('create_time','<',$time)->delete();//删除已过期的formid
        $result = self::where('wu_id','=',$wu_id)
                    ->where('uid','=',$uid)
                    ->where('create_time','>',$time)
                    ->field('id,formId,min(create_time)')->find();
        return $result;
    }

}